package com.ef.web.action;

import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;

import com.ef.constant.ConfirmMessage;
import com.ef.domain.School;
import com.ef.service.SchoolService;
import com.ef.util.CustomExample;

public class SchoolAction extends BaseAction<School> {

	
	private static final long serialVersionUID = 1L;
	
	protected final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
	.getLog(SchoolAction.class);
	private SchoolService schoolService;
	
	
	@SuppressWarnings("serial")
	public String list(){
		this.listResult = schoolService.findByExample(
				new CustomExample<School>(this.getModel()) {

					public void appendCondition(Criteria criteria) {
						this.enableLike(MatchMode.ANYWHERE);
					}
				}, this.getStartIndex(), this.getPageSize());
		return LIST;
	}
	
	public String edit(){
		
		return EDIT;
	}
	public String save(){
		
		School school  = this.getModel();
		schoolService.saveOrUpdate(school);
		this.setResult(ConfirmMessage.SCHOOL);
		
		return EDIT;
	}
	public String delete(){
		String ids = getRequest().getParameter("ids");
		String[] id = ids.split(",");
		for (String i : id) {
			schoolService.delete(schoolService.findById(Long.valueOf(i)));
		}
		return DELETE;
	}

	public SchoolService getSchoolService() {
		return schoolService;
	}

	public void setSchoolService(SchoolService schoolService) {
		this.schoolService = schoolService;
	}
	
	
}
